package besteAukera;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Vector;

public class Desmultiplexorea extends Konbinazionalak {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Color kolorea;
	private Vector<Hanka> hankaBektorea = new Vector<Hanka>();
	private Vector<Hanka> sarreraBektorea = new Vector<Hanka>();
	private Hanka s1, s2, i1, s3, i2, i3, i4;

	public Desmultiplexorea(int x1, int y1, int hankaKop, int sarreraKopMax,
			String mota, Color kolorea) {
		super(x1, y1, hankaKop, sarreraKopMax, mota, kolorea);
		// TODO Auto-generated constructor stub

		i1 = new Hanka(x + 60, y + 12, "positiboa", "i", 3, this, "h", "ez",false);
		i2 = new Hanka(x + 60, y + 30, "positiboa", "i", 4, this, "h", "ez",false);
		i3 = new Hanka(x + 60, y + 48, "positiboa", "i", 5, this, "h", "ez",false);
		i4 = new Hanka(x + 60, y + 66, "positiboa", "i", 6, this, "h", "ez",false);
		s1 = new Hanka(x - 20, y + 40, "positiboa", "s", 0, this, "h", "ez",false);

		// kontrola
		s2 = new Hanka(x + 15, y + 76, "positiboa", "s", 1, this, "b", "bai",true);
		s3 = new Hanka(x + 28, y + 88, "positiboa", "s", 2, this, "b", "bai",true);
		// Gaikuntza

		lotList[0] = s1;
		lotList[1] = s2;
		lotList[2] = s3;

		lotList[3] = i1;
		lotList[4] = i2;
		lotList[5] = i3;
		lotList[6] = i4;

	}

	public void marraztu(Graphics g) {

		if (getAukeratua() == true) {
			kolorea = Color.GRAY;
		} else {
			kolorea = Color.black;
		}
		g.setColor(kolorea);
		// goikoa
		g.drawLine(x + 40, y, x + 40, y + 80);
		g.drawLine(x + 40, y, x, y + 40);
		g.drawLine(x + 40, y + 80, x, y + 40);

		s1.marraztu(g);
		s2.marraztu(g);

		s3.marraztu(g);
		i1.marraztu(g);
		i2.marraztu(g);
		i3.marraztu(g);
		i4.marraztu(g);
		g.setColor(Color.black);
		g.drawString("1:4", x + 15, y + 45);

	}

	public boolean barruanDago(int x, int y) {
		if ((x > this.x) && (x < (this.x + 60)) && (y > this.y)
				&& (y < (this.y + 80))) {
			return true;
		}
		return false;

	}

	@Override
	public void funtzioLogikoa(Integer... values) {

		// TODO Auto-generated method stub

		lotList[3].getIrteera().setBalioa(
				s1.getSarrera().getBalioa() & ~(s2.getSarrera().getBalioa())
						& ~(s3.getSarrera().getBalioa()));
		lotList[4].getIrteera().setBalioa(
				s1.getSarrera().getBalioa() & ~(s2.getSarrera().getBalioa())
						& s3.getSarrera().getBalioa());
		lotList[5].getIrteera().setBalioa(
				s1.getSarrera().getBalioa() & s2.getSarrera().getBalioa()
						& ~(s3.getSarrera().getBalioa()));
		lotList[6].getIrteera().setBalioa(
				s1.getSarrera().getBalioa() & s2.getSarrera().getBalioa()
						& s3.getSarrera().getBalioa());
	}

	@Override
	public Vector<Hanka> getHankak() {
		// TODO Auto-generated method stub

		hankaBektorea = new Vector<Hanka>();
		hankaBektorea.addElement(s1);
		hankaBektorea.addElement(s2);
		hankaBektorea.addElement(s3);

		hankaBektorea.addElement(i1);
		hankaBektorea.addElement(i2);
		hankaBektorea.addElement(i3);
		hankaBektorea.addElement(i4);

		return hankaBektorea;
	}

	@Override
	public Vector<Hanka> getSarreraHankak() {
		// TODO Auto-generated method stub

		sarreraBektorea = new Vector<Hanka>();
		sarreraBektorea.addElement(s1);
		sarreraBektorea.addElement(s2);
		sarreraBektorea.addElement(s3);

		return sarreraBektorea;
	}

}
